﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication.Code;
using Telerik.Web.UI;
using Company.Merchandising.BusinessLayer.DataEntities;
using Company.Merchandising.Utilities.LinqToEntities;
using Company.Merchandising.BusinessLayer.DataTransferObjects;

namespace WebApplication.Controls.Management.Dictionaries
{
	public partial class ChainStoresEditControl : EntityUserControl
	{
		protected void Page_Init(object sender, EventArgs e)
		{
			GridEditableItem item = this.Parent.NamingContainer as GridEditableItem;
			if (item == null || item.DataItem == null)
			{
				return;
			}

			if (item.DataItem is GridInsertionObject)
			{
				btUpdate.Visible = false;
				return;
			}

			ChainStore editedChainStore = EntityDataSourceExtensions.GetItemObject<ChainStore>(item.DataItem);
			if (editedChainStore != null)
			{
				btInsert.Visible = false;
				tbChainStoreName.Text = editedChainStore.Name;
				return;
			}
		}

		public DTOChainStore EditedChainStore
		{
			get
			{
				return new DTOChainStore() { Name = tbChainStoreName.Text };
			}
		}
	}
}